package com.hotelvip.common.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 跨配置cors允许访问的策略
 * @author Lzh
 * @date 2020/11/27 11:31
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedMethods("POST", "GET", "PUT", "OPTIONS", "DELETE") //定义允许跨域的请求类型
                .allowedOriginPatterns("*")           //任意网址都可以访问
                .allowCredentials(true)         //是否允许携带cookie
                .maxAge(1800);                 //设定请求长链接超时时间.
    }

}
